<template>
  用户名:<input type="text" v-model="userName"><br/>
  密码:<input type="text" v-model="password"><br/>
  <button @click="login">登录</button>
  <span v-if="error" style="background-color: red">账号密码错误</span>
</template>

<script>
export default {
  name: "login",
  data(){
    return{
      userName:'',
      password:'',
      error:false
    }
  },
  methods:{
    login(){
      const self = this //因为匿名方法内部不能使用this
      this.$http.get('/user/login?userName='+this.userName+'&password='+this.password).then(function(res){
        if(res.data){
          localStorage.setItem('user',self.userName)
          self.$router.push('/')
        }else{
          self.error = true
        }
      })
    }
  }
}
</script>

<style scoped>

</style>